<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Listing/classes/PhpFox_ComponentEditGroups.class.php, $Author:  $ */



/** Display list bulletins
 * 
 * Parameters:
 *  1. oUser (mandatory) - user account object
 * 
 * @package module.bulletin
 * @version $Id: 
 *   PHPFox Team ()
 */
class PhpFox_Mod_Listing_ComponentEditGroups extends BaseComponent
{
	function process()
	{
	    //check permissions
        $oSecurityService = App::getModuleService('Account', 'Security');
		/* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
		$oSecurityService->checkPerm('groups', array('full')); 
        
        $oListingService = $this->_oModule->getService('Listing');
        /* @var $oGroupsService PhpFox_Mod_Groups_ServiceGroups */
        
        $oReq = &App::getRequest();
        /* @var $oReq Request */
        
        $oTpl = $this->_oModule->getTemplate();

        $iGroupId = $oReq->getInt('id', 0);
        
        $bIsDeleted = false;
        $bIsInserted = false;                
        
        $sAction = $oReq->getAction();
        $sName = $oReq->get('name', '');
        $iCategoryId = $oReq->getInt('id');
        
	    switch ($oReq->getAction())
	    {
	        case 'delete':
	            if(!$oListingService->deleteCategory($iCategoryId))
	            	$this->addErrors($oListingService->getErrors());
	            else
	            	App::gotoUrl('admin.sections.classifieds',array(),App::format('you_have_deleted_classified_categor').': '.$iCategoryId);       
	            break;
	        case 'create':
	            $sName = $oReq->get('name');
                if(!$oListingService->editCategory($sName))
                    $this->addErrors(App::format('Mod_Listing.same.cat'));
                else
                	App::gotoUrl('admin.sections.classifieds',array(),App::format('you_have_created_the_classified_cat').': '.$sName);
	            break;
	        case 'update':
	            $sName = $oReq->get('name');
                if(!$oListingService->editCategory($sName, $iCategoryId))
                    $this->addErrors(App::format('Mod_Listing.same.cat'));
	            else
                	App::gotoUrl('admin.sections.classifieds',array(),App::format('you_have_edited_the_classified_cate').': '.$sName);
	            break;
	    }
	    
	    $aList = $oListingService->getCategories();

        $oTpl->assign(array(
            'sName' =>$sName,
            'iCategoryId' => $iCategoryId,
            'sAction' => $sAction,
            'aList' => $aList,
        ));
	    

        $oTpl->assignSrc(array(
                                'aErrors' => $this->getErrors(),
                                ));
                                
        $srcHtml = $oTpl->fetch('EditGroups.html');
		return $srcHtml;                                
	}
}
?>